package org.bigjava.novelplatform.common.web.listener;

import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.bigjava.novelplatform.common.utils.RedisUtils;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import static org.bigjava.novelplatform.common.constant.NovelInfoConstant.SESSION_USER;

/**
 * @author ykh
 */
@Slf4j
public class SessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent event) {
        final HttpSession session = event.getSession();
//        final RedisUtils bean = SpringUtil.getBean(RedisUtils.class);
//        bean.set(session,session.getId(),null);
        log.info("创建session{}",session);
        // Session创建时执行的操作
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        final HttpSession session = event.getSession();
//        final RedisUtils bean = SpringUtil.getBean(RedisUtils.class);
//        bean.del(session.getId());
        log.info("销毁session{}",session);
        // Session失效时执行的操作
    }
}
